﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace iLangl.Model
{
	public class PluginRegistrationRequestContext : BaseContext
	{
		PluginRegistration registration = null;

		public override void SetContext(object context)
		{
			base.SetContext(context);

			if (context is PluginRegistration)
			{
				registration = context as PluginRegistration;
			}
		}

		public override object GetContext()
		{
			if (registration == null)
			{
				return string.Empty;
			}

			startDocument();
			writer.WriteStartElement("PluginRegistration");

			writer.WriteAttributeString("pluginId", registration.PluginId);
			writer.WriteAttributeString("pluginName", registration.PluginName);
			writer.WriteAttributeString("pluginVersion", registration.PluginVersion);
			writer.WriteAttributeString("licenseOwner", registration.PrimaryContactId);
			writer.WriteAttributeString("sessionId", registration.SessionId);
			writer.WriteAttributeString("pushURI", registration.PushURIAddress);

			InitExtendedAttributes(writer, registration);
			InitExtendedElements(writer, registration);

			if (registration.Company != null)
			{
				CompanyRequestContext companyRequestContext = new CompanyRequestContext();
				companyRequestContext.SetContext(registration.Company);
				companyRequestContext.Write(writer);

			}
			writer.WriteEndElement();

			return endDocument();
		}
	}
}
